<template>
  <div class="productItem" @click="$router.push('/detail/' + item.id)">
    <div class="img">
      <van-image lazy-load fit="cover" :src="item.image" />
    </div>
    <div :class="['info', { min: min }]">
      <div class="name">
        {{ item.store_name }}
      </div>
      <div class="price">￥{{ item.price }}</div>
      <div class="bottom">
        <div class="vip_price">￥{{ item.vip_price }}</div>
        <div class="sales">已售{{ item.sales | formatNum }}件</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  props: {
    item: Object,
    min: {
      type: Boolean,
      default: false,
    },
  },
  filters: {
    formatNum(value) {
      return value > 10000
        ? (value / 10000).toFixed(1).replace(/\.0$/, "") + "w"
        : value > 1000
        ? (value / 1000).toFixed(1).replace(/\.0$/, "") + "k"
        : value;
    },
  },
};
</script>

<style lang="less" scoped>
.productItem {
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
  .img {
    width: 100%;
    height: 0;
    padding-bottom: 100%;
    position: relative;
    .van-image {
      width: 100%;
      height: 100%;
      position: absolute;
    }
  }
  .info {
    width: 100%;
    box-sizing: border-box;
    padding: 5px;
    .name {
      font-size: 15px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .price {
      font-weight: bold;
      font-size: 16px;
      color: #24c1bb;
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      font-size: 12px;
      .vip_price {
        font-weight: bold;
        color: #282828;
        &::after {
          content: "VIP";
          line-height: 12px;
          padding: 2px 6px;
          transform: scale(0.65);
          display: inline-block;
          color: rgb(248, 226, 125);
          background-color: #282828;
          border-radius: 5px;
        }
      }
      .sales {
        color: #ccc;
      }
    }
    &.min {
      padding: 5px 8px;
      .name {
        font-size: 12px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        white-space: unset;
        text-overflow: unset;
      }
      .price {
        font-size: 14px;
        display: none;
      }
      .bottom {
        transform-origin: left;
        .sales {
          display: none;
        }
      }
    }
  }
}
</style>